Convert Date DDMMYY to DateTime

Convert Date DDMMYY to DateTime

There is no defined format for DDMMYY so we need to do some manipulation to convert given format as datetime

eg: - We need to convert '311220' to '2020-12-31' 

First We need to convert date in sql supported format 

SELECT STUFF(STUFF('200121', 3, 0, '/'),6,0,'/') 

output:


Then we convert it to sql format

SELECT CONVERT(Datetime,STUFF(STUFF('200121', 3, 0, '/'),6,0,'/'),3);


Login for comment